package net.mihome.app.adapter;

import java.util.ArrayList;
import java.util.List;

import net.mihome.app.bean.Advert;
import net.mihome.app.common.BitmapManager;
import net.mihome.app.R;


import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SampleAdapter extends ArrayAdapter<Advert> {

    private static final String TAG = "SampleAdapter";
    private LayoutInflater listContainer;
	 private List<Advert> listItems=new ArrayList<Advert>();
	 private BitmapManager bmpManager;
	 private Context context;

    public SampleAdapter(Context context, int resource, List<Advert> objects) {
		super(context, resource, objects);
		listContainer = LayoutInflater.from(context);
		listItems=objects;
		bmpManager=new BitmapManager(BitmapFactory.decodeResource(context.getResources(), R.drawable.tweet_confirm_dialog_load));
		// TODO Auto-generated constructor stub
	}
    public SampleAdapter(final Context context, final int textViewResourceId) {
        super(context, textViewResourceId);
        listContainer = LayoutInflater.from(context);
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
         View  v = listContainer.inflate(R.layout.list_item_sample, parent, false);
         ImageView ivImageView=(ImageView) v.findViewById(R.id.scg_image_id);
         bmpManager.loadBitmap(listItems.get(position).getImg(),ivImageView);
         TextView textView=(TextView) v.findViewById(R.id.scg_text_id);
         textView.setText(listItems.get(position).getContent()); 
         return v;
    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listItems.size();
	}
	@Override
	public Advert getItem(int position) {
		// TODO Auto-generated method stub
		return listItems.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return listItems.get(position).getId();
	}

}
